﻿using System;
using System.Collections.Generic;
using System.Text;
using System.ServiceProcess;
namespace MyWindowsService
{
    /// <summary>
    /// 本对象用于配合.NET框架的InstallUtil.exe的工作，用于向Windows系统安装和卸载服务
    /// </summary>
    [System.ComponentModel.RunInstaller( true )]
    public class MyServiceInstaller : System.Configuration.Install.Installer
    {
        /// <summary>
        /// 初始化对象
        /// </summary>
        public MyServiceInstaller()
        {
            System.ServiceProcess.ServiceInstaller installer = new ServiceInstaller();
            installer.Description = "《C#发现之旅》系列课程的演示Windows服务";
            installer.DisplayName = "我的文件系统监视服务";
            installer.ServiceName = "MyFileSystemWatcher";
            installer.StartType = ServiceStartMode.Manual;

            System.ServiceProcess.ServiceProcessInstaller proinstaller = new System.ServiceProcess.ServiceProcessInstaller();
            // 采用本地系统帐户运行服务
            // 若采用其他帐户则可能没有权限访问数据库
            proinstaller.Account = System.ServiceProcess.ServiceAccount.LocalSystem ;

            this.Installers.Add( installer );
            this.Installers.Add(proinstaller);
        }
    }
}
